@echo off
setlocal enabledelayedexpansion

for %%i in (base,cgproto) do (
set src=%~dp0..\..\proto\%%i.proto
set dst=%~dp0..\..\csproto-lib\%%i.pb.cc
call :protoc !src! !dst!
)

goto :end

:protoc
if not exist %~dpnx1 goto terminate
if not exist %~dpnx2 goto run_protoc
if "%~t1" GTR "%~t2" goto run_protoc
if "%~t2" GTR "%~t1" (echo Do nothing for %~dpnx1) else (
set src_attr=%~a1
if "!src_attr:~2,1!" EQU "a" goto run_protoc  
echo Do nothing for %~dpnx1 because of no modify
goto :terminate
:run_protoc
%~dp0protoc.exe -I=%~dp1 --cpp_out=%~dp2 %~dpnx1
IF %ERRORLEVEL% EQU 0 (
attrib -a %~dpnx1
echo %~nx2 have been generated!
goto terminate)
echo %~nx2 generated error!
)

goto :terminate

:end
pause

:terminate